# -*- coding: utf-8 -*-

try:
    from spider import Gather, Parser
except ImportError:
    from __init__ import Gather, Parser

class Alexa(Gather, Parser):
    URL = "http://data.alexa.com/data?cli=10&dat=snbamz&url=%s"

    def __init__(self, domain):
        url = self.URL % domain
        Gather.__init__(self, url)
        Parser.__init__(self, self.gather())

    def parser(self):
        soup = self._soup()
        popularity_tag = soup.find('popularity')
        if popularity_tag:
            rank = int(popularity_tag["text"])
            return rank

        return None


if __name__ == '__main__':
    alexa = Alexa("http://www.qq.com")
    print alexa.parser()
